﻿/*
 SmallJS toolkit
 Copyright (c) 2013 Walter M. Soto Reyes
 http://www.smalljs.com or https://smalljs.codeplex.com
 License: https://smalljs.codeplex.com/license
*/

(function () {
    "use strict";
    if (!document.querySelectorAll) {
        //for IE6,IE7 compatibility include any of the following libraries:
        if (window.Sizzle) {
            //URL: http://sizzlejs.com
            document.querySelectorAll = Sizzle;
        } else if (window.Selector) {
            //URL: http://www.llamalab.com/js/selector/
            document.querySelectorAll = Selector;
        }
    }
     
     var isDefined = function (obj) { 
         return (typeof (obj) !== 'undefined');
     };

    var SmallJS = (function () {
         
        var sj = function () {
            /// <signature>
            ///   <summary>Accepts one or more object ids</summary>
            ///   <param name="id" type="DOM object">DOM object id or reference</param> 
            /// </signature>
            /// <signature>
            ///   <summary>Accepts one or more object names</summary>
            ///   <param name="name" type="DOM object">Form object name or reference</param> 
            /// </signature>
            /// <signature>
            ///   <summary>Accepts a query selector (Ex. div.class) </summary>
            ///   <param name="query selector" type="DOM object">Query selector (Note: works on IE8+)</param> 
            /// </signature>
            var o = []; 
            if (arguments.length > 0) {
                for (var i = 0, m =arguments.length; i < m; i++) { 
                    var e = $(arguments[i]);
                        if (isDefined(e)) {
                            if (isDefined(e.length) && e.length > 0 && e.tagName !== 'SELECT') {
                                for (var le = 0; le < e.length; le++) {
                                    var lv = $(e[le]);
                                    if (isDefined(lv)) { o.push(lv); }
                                }
                            } else {
                                if (isDefined(e.length) && e.length > 0 && e.tagName === 'SELECT') {
                                    o.push(e);
                                } else if(isDefined(e.length) && e.length == 0) {
                                }else{
                                    o.push(e);
                                }
                                
                            }
                        } 
                }
            } else {
                return st;
            } 
            plugins.me = o;
            return new local.instance(plugins);
        };
 
        var $ = function () {
            ///	<summary>
            /// 	1: Get DOM element by id, name, class name, or query selector
            ///	</summary>
            ///	<returns type="element" />
            var elements = [], doc = document, i = 0,m=0;

            for (i = 0, m = arguments.length; i < m; i++) {
                var element = null, arg = arguments[i];
                if (typeof arg === 'string') {
                    element = doc.getElementById(arg);
                    if (element === null) {
                        element = doc.getElementsByTagName(arg);
                        if (element.length === 1) { element = element[0]; }else if (element.length > 1) { return element; }
                    }
                    if (element.length === 0) {
                        element = doc.getElementsByName(arg);
                        if (element.length === 1) { element = element[0]; } else if (element.length > 1) { return element; }
                    }
                    if (element.length === 0) {
                        if (arg.length > 0 && arg.charAt(0) == '.') {
                            if (doc.getElementsByClassName) {
                                element = doc.getElementsByClassName(arg.substring(1));
                                if (element.length === 1) { element = element[0]; }
                            }
                            
                        }
                    }
                    if (element.length === 0) {
                        if (doc.querySelectorAll) {
                            try {
                                element = doc.querySelectorAll(arg);
                            } catch (e) {
                                //console.log(e);
                            }
                        }
                        return element;
                    }
                } else {
                    element = arg;
                }
                if (arguments.length === 1) {
                    return element;
                }
                if (element !== null) {
                    if (element.length) {
                        for (var s = 0, max = element.length; s < max; s++) {
                            elements.push(element[s]);
                        }
                    } else {
                        elements.push(element);
                    }
                }
            }
            return elements;
        };
 
        var  xml = {
            parse: function (text) {
                ///	<summary>
                ///	Parse a string to XML
                ///	</summary>
                ///	<param name="text" type="string">
                ///	 string to be parsed to XML
                ///	</param>
                ///	<returns type="XML" />
                var xmlDoc;
                if (window.DOMParser) {
                    xmlParser = new DOMParser();
                    xmlDoc = xmlParser.parseFromString(text, "text/xml");
                } else { // Internet Explorer
                    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                    xmlDoc.async = "false";
                    xmlDoc.loadXML(text);
                }
                return xmlDoc;
            }
        };

        var vars = {
            onReady: null,
            readyExecuted: false
        };
        
        var st = { 
            attach: function (object, action, fn) {
                ///	<summary>
                /// Attach an event to a DOM element
                ///	</summary>
                ///	<param name="object" type="object">
                /// Element id, name, or DOM element
                ///	</param>
                ///	<param name="action" type="string">
                /// Event name
                ///	</param>
                ///	<param name="fn" type="function">
                /// Function to execute
                ///	</param>
                var o = $(object);
                if (isDefined(o)) { 
                    if (o.addEventListener) {
                        if (action.substring(0, 2) === "on") {
                            action = action.substring(2);
                        }
                        o.addEventListener(action, fn, false);
                    } else if (o.attachEvent) {
                        if (action.length > 2) {
                            if (action.substring(0, 2) !== "on") {
                                action = 'on' + action;
                            }
                        }
                        o.attachEvent(action, fn);
                    }
                }
            
            },
            detach: function (object, action, fn) {
                ///	<summary>
                /// Detach an event from a DOM element.
                ///	</summary>
                ///	<param name="object" type="object">
                /// Element id, name, or DOM element.
                ///	</param>
                ///	<param name="action" type="string">
                /// Event name.
                ///	</param>
                ///	<param name="fn" type="function">
                /// Function to execute
                ///	</param>
                o = $(object);
                if (isDefined(o)) {
                    if (o.removeEventListener) {
                        if (action.substring(0, 2) === "on") {
                            action = action.substring(2);
                        }
                        o.removeEventListener(action, fn, false);
                    } else if (o.detachEvent) {
                        if (action.length > 2) {
                            if (action.substring(0, 2) !== "on") {
                                action = 'on' + action;
                            }
                        }
                        o.detachEvent(action, fn);
                    }
                } 
            },
            onload: function (fn) {
                ///	<summary>
                /// Execute multiple functions in the window.onload method.
                ///	</summary>
                ///	<param name="fn" type="function">
                /// Function to execute.
                ///	</param>
                var cur = window.onload;
                if (typeof window.onload !== 'function') {
                    window.onload = fn;
                } else {
                    if (typeof fn === 'function') {
                        window.onload = function () {
                            if (cur) {
                                cur();
                            }
                            fn();
                        };
                    }
                }
            }, 
            ready: function (fn) {
         
                if (typeof vars.onReady !== 'function') {
                    vars.onReady = fn;
                } else {
                    var cur = vars.onReady;
                    vars.onReady = function () {
                        if (cur) {
                            cur();
                        }
                        fn();
                    };
                }

                if (document.addEventListener) {
                    document.addEventListener('DOMContentLoaded', function () {
                        if (!vars.readyExecuted) {
                            vars.onReady();
                            vars.readyExecuted = true;
                        } 
                    }, false);
                } else {
                    st.onload(fn);
                } 
            },
     
            //Wait to execute
            wait: function (delay, fn) {
                ///<summary>
                /// Execute a function after a delay
                ///</summary>
                ///<param name="delay" type="milliseconds">
                /// Time to wait
                ///</param>
                ///<param name="fn" type="function">
                /// Function to execute after the delay
                ///</param>
                if (!isDefined(delay)) {
                    delay = 1000;
                }
                window.setTimeout(function () {
                    if (typeof (fn) !== 'undefined') {
                        if (typeof (fn) === 'function') {
                            fn();
                        }
                    }
                }, delay);
            },

            //QueryString
            queryString: function (key) {
                ///<summary>
                /// Ready querystring value
                ///</summary>
                ///<param name="key" type="string">
                /// Querystring parameter name
                ///</param>
                ///	<returns type="string" /> 
                var args = window.location.href.split("?");
                if (args.length === 2) {
                    var arg;
                    if (args[1].indexOf("&") !== -1) {
                        arg = args[1].split("&");
                        if (arg.length > 0) {
                            for (var i = 0, m = arg.length; i < m; i++) {
                                var sArg = arg[i].split("=");
                                if (sArg.length > 0) {
                                    if ((sArg[0] == key)) {
                                        return sArg[1];
                                    }
                                }
                            }
                        }
                    } else {
                        arg = args[1].split("=");
                        if (arg.length > 0) {
                            if ((arg[0] === key)) {
                                return arg[1];
                            }
                        }
                    }
                }
                return "";
            },
            forms: {
                clear: function (form) {
                    ///	<summary>
                    ///  Clear all elements in a form
                    ///	</summary>
                    ///	<param name="form" type="identifier">
                    ///	 Form id, name, or reference
                    ///	</param> 
                    var f = $(form);
                    if (isDefined(f)) {
                        for (var i = 0, m = f.elements.length; i < m; i++) {
                            if (typeof (f.elements[i].name) !== 'undefined') {
                                var name = (f.elements[i].name.length > 0) ? f.elements[i].name : f.elements[i].type + i;
                                if (f.elements[i].type === "select-multiple" || f.elements[i].type === "select-one") {
                                    st.forms.option.clear(f.elements[i]);
                                } else if (f.elements[i].type === "checkbox" || f.elements[i].type === "radio") {
                                    f.elements[i].checked = false;
                                } else {
                                    if (f.elements[i].type !== "button" && f.elements[i].type !== "submit") {
                                        f.elements[i].value = "";
                                    }
                                }
                            }
                        }
                    }
                  
                },
                fetch: function (form) {
                    ///	<summary>
                    ///  Fetch values of elements in a form into an array
                    ///	</summary>
                    ///	<param name="form" type="identifier">
                    ///	 Form id, name, or reference
                    ///	</param>
                    ///	<returns type="form items {name,value}" />
                    var items = [],f = $(form);
                    if (isDefined(f)) {
                        for (var i = 0, m = f.elements.length; i < m; i++) {
                            if (typeof (f.elements[i].name) !== 'undefined') { 
                                var name = (f.elements[i].name.length > 0) ? f.elements[i].name : f.elements[i].type + i; 
                                if (f.elements[i].type === "select-multiple" || f.elements[i].type === "select-one") {
                                    items.push({
                                        name: name,
                                        value: st.forms.option.value(f.elements[i])
                                    });
                                } else if (f.elements[i].type === "checkbox" || f.elements[i].type === "radio") {
                                    if (f.elements[i].checked) {
                                        items.push({
                                            name: name,
                                            value: f.elements[i].value
                                        });
                                    }
                                } else {
                                    if (f.elements[i].type !== "button" && f.elements[i].type !== "submit") {
                                        items.push({
                                            name: name,
                                            value: f.elements[i].value
                                        });
                                    }
                                }
                            }
                        }
                    } 
                    return items;
                },
                radio: {
                    index: function (id) {
                        ///	<summary>
                        ///	Return selected index from a radio element
                        ///	</summary>
                        ///	<param name="id" type="identifier">
                        ///	 Element id, name, or reference
                        ///	</param>
                        ///	<returns type="number" />
                        if (typeof ($(id).length) !== 'undefined') {
                            var index = -1,_obj = $(id);
                            for (var i = 0, m = _obj.length; i < m; i++) {
                                if (_obj[i].checked) {
                                    index = i;
                                    break;
                                }
                            }
                            return index;
                        }
                        return -1;
                    },
                    value: function (id) {
                        ///	<summary>
                        ///	Return selected value from a radio element
                        ///	</summary>
                        ///	<param name="id" type="identifier">
                        ///	 Element id, name, or reference
                        ///	</param>
                        ///	<returns type="object" />
                        var index = st.forms.radio.index(id);
                        if (index !== -1) {
                            return $(id)[index].value;
                        }
                        return "";
                    }
                },
                option: {
                    select: function (id, val) {
                        ///	<summary>
                        ///	Select an element in a list
                        ///	</summary>
                        ///	<param name="id" type="identifier">
                        ///	 Element id, name, or reference
                        ///	</param>
                        ///	<param name="val" type="value">
                        ///	 Value of the element to be selected
                        ///	</param>
                        for (var i = 0, m = $(id).length ; i < m; i++) {
                            if ($(id).options[i].value === val) {
                                $(id).options[i].selected = true;
                            }
                        }
                    },
                    index: function (id) {
                        ///	<summary>
                        ///	Return selected index from an option element
                        ///	</summary>
                        ///	<param name="id" type="identifier">
                        ///	 Element id, name, or reference
                        ///	</param>
                        ///	<returns type="number or array" />
                        if (isDefined($(id).selectedIndex)) {
                            if ($(id).selectedIndex !== -1) {
                                if ($(id).multiple) {
                                    var v = []; 
                                    for (var i = 0, m = $(id).length; i < m; i++) {
                                        if ($(id).options[i].selected) { 
                                            v.push(i); 
                                        }
                                    }
                                    return v;
                                } else {
                                    return $(id).selectedIndex;
                                }
                            }
                        }
                        return -1;
                    },
                    value: function (id) {
                        ///<summary>
                        ///	Return selected value from an option element
                        ///</summary>
                        ///<param name="id" type="identifier">
                        ///	 Element id, name, or reference
                        ///</param>
                        ///<returns type="object or array" /> 
                        if ($(id).multiple) {
                            var v = []; 
                            for (var i = 0, m = $(id).length; i < m; i++) {
                                if ($(id).options[i].selected) { 
                                    v.push($(id).options[i].value); 
                                }
                            }
                            return v;
                        } else {
                            return $(id).options[st.forms.option.index(id)].value;
                        }
                    },
                    clear: function (id) {
                        ///<summary>
                        ///	Clear all elements from an option element
                        ///</summary>
                        ///<param name="id" type="identifier">
                        ///	Element id, name, or reference
                        ///</param> 
                        for (var i = 0, m = $(id).length; i < m; i++) {
                            $(id).options[i].selected = false;
                        }
                    },
                    text: function (id) {
                        ///<summary>
                        ///	Return selected text from an option element
                        ///</summary>
                        ///<param name="id" type="identifier">
                        ///	Element id, name, or reference
                        ///</param>
                        ///<returns type="string or array" />
                        if ($(id).multiple) {
                            var v = [];
                            for (var i = 0, m = $(id).length; i < m; i++) {
                                if ($(id).options[i].selected) { 
                                    v.push($(id).options[i].text); 
                                }
                            }
                            return v;
                        } else {
                            return $(id).options[st.forms.option.index(id)].text;
                        }
                    }
                }
            },
            //Ajax
            ajax: {
                url: {
                    encode: function (uri) {   
                        ///	<summary>
                        ///	Encode URL
                        ///	</summary>
                        ///	<param name="uri" type="string">
                        ///	 URL to encode
                        ///	</param>
                        ///	<returns type="string" /> 
                        return encodeURIComponent(uri);
                    },
                    decode: function (uri) {
                        ///	<summary>
                        ///	Decode URL
                        ///	</summary>
                        ///	<param name="uri" type="string">
                        ///	 URL to decode
                        ///	</param>
                        ///	<returns type="string" />
                        return decodeURIComponent(uri);
                    }
                }, 
                contentType: {
                    JSON: 'application/json; charset=UTF-8',
                    FORM: 'application/x-www-form-urlencoded'
                },
                settings: {
                    ps: function (url) {
                        ///	<summary>
                        ///	Determine if a parameter will begin with ? or &
                        ///	</summary>
                        ///	<param name="url" type="string">
                        ///	 Ajax call url
                        ///	</param>
                        var _s = '';
                        if (url.indexOf('?') == -1) {
                            _s = '?';
                        } else {
                            if (url.indexOf('&') == -1 && url.indexOf('?') == url.length - 1) {
                                _s = '';
                            } else {
                                _s = '&';
                            }
                        }
                        return _s;
                    },
                    getParameters: function (params, url, encode) {
                        ///	<summary>
                        ///	Get parameters to initiate request
                        ///	</summary>
                        ///	<param name="params" type="string[]">
                        ///	 Parameters array
                        ///	</param>
                        ///	<param name="url" type="string">
                        ///	 Request URL
                        ///	</param>
                        ///	<param name="encode" type="bool">
                        ///	 Encode URL?
                        ///	</param>
                        ///	<returns type="string" />
                        var _s = st.ajax.settings.ps(url),_p = ''; 
                        for (var p in params) {
                            if (isDefined(params[p])) {
                                var par = params[p];
                                if (isDefined(encode)) {
                                    par = encodeURIComponent(par);
                                }
                                _p += _s + p + '=' + par;
                                if (_s != '&') {
                                    _s = '&';
                                }
                            }
                        }
                        return _p;
                    }, 
                    resultFormat: {
                        String: 'String',
                        Xml: 'Xml',
                        Status: 'Status',
                        Json: 'Json'
                    },
                    format: 'String'
                },
                xmlhttpObject: function () {
                    ///	<summary>
                    ///	Get XMLHttpObject
                    ///	</summary>
                    ///	<returns type="XMLHttp" />
                    if (window.XMLHttpRequest) {
                        return new XMLHttpRequest();
                    } else {//IE 5,6
                        try {
                            return new ActiveXObject("'Msxml2.XMLHTTP.6.0'");
                        } catch (e) {
                            try {
                                return new ActiveXObject('Msxml2.XMLHTTP.3.0');
                            } catch (e2) {
                                try {
                                    return new ActiveXObject("Microsoft.XMLhttp");
                                } catch (ex) {
                                    return null; //Browser doesn't support ajax
                                }
                            }
                        }
                    }
                },
                file: function (req) {
                    ///	<summary>
                    ///	Post a file via XMLHttpRequest (IE9 or lower doesn't support the file api)
                    ///	</summary>
                    ///	<param name="req" type="json">
                    ///	 { 
                    ///      url: '',
                    ///      file:'posted file',
                    ///      onError:function(),
                    ///      onAbort:function(),
                    ///      onLoad:function(),
                    ///      onLoadStart:function(),
                    ///      onLoadEnd:function(),
                    ///      onProgress:function(),
                    ///      onTimeout:function(),
                    ///      onResponse:function()
                    ///  }
                    ///	</param> 
                    (function (xH) {
                        var format = isDefined(req.resultType) ? req.resultType : "JSON";
                        if (isDefined(req.onAbort)) { xH.upload.onabort = req.onAbort; }
                        if (isDefined(req.onError)) { xH.upload.onerror = req.onError; }
                        if (isDefined(req.onLoad)) { xH.upload.onload = req.onLoad; }
                        if (isDefined(req.onLoadStart)) { xH.upload.onloadstart = req.onLoadStart; }
                        if (isDefined(req.onLoadEnd)) { xH.upload.onloadend = req.onLoadEnd; }
                        if (isDefined(req.onProgress)) { xH.upload.onprogress = req.onProgress; }
                        if (isDefined(req.onTimeout)) { xH.upload.ontimeout = req.onTimeout; }
                        xH.open('POST', req.url);
                        xH.setRequestHeader("Cache-Control", "no-cache");
                        xH.setRequestHeader("X-Requested-With", "XMLHttpRequest");
                        xH.setRequestHeader("X-File-Name", req.file.name);
                        xH.onreadystatechange = function () {

                            if (xH.readyState == 4) {
                                if (xH.responseText.length > 0) {
                                    var result = "";
                                    switch (format.toString().toUpperCase()) {
                                        case 'STRING': result = xH.responseText; //Text
                                            break;
                                        case 'XML': result = xml.parse(xH.responseText);
                                            break;
                                        case 'JSON': result = xH.responseText;
                                            if (typeof (JSON) !== 'undefined') {
                                                result = JSON.parse(result);
                                            }
                                            break;
                                        default: result = xH.responseText;
                                            break;
                                    }
                                    if (xH.status == 200) {
                                        if (typeof req.onResponse == "function") {
                                            req.onResponse(result);
                                        }
                                    }
                                }
                                xH = null;//End
                            }

                        };

                        xH.send(req.file);
                    })(st.ajax.xmlhttpObject());
                },
                call: function (req) {
                    ///	<summary>
                    ///	Perform an Ajax call
                    ///	</summary>
                    ///	<param name="req" type="json">
                    ///	 {
                    ///      method: 'Post'|'Get'|'Header',
                    ///      url: '',
                    ///      data: {
                    ///       'Param 1': 'Value 1',
                    ///       'Param 2': 'Value 2'
                    ///      },
                    ///      onTimeout:function(),
                    ///      timeout:'wait for response time',
                    ///      form:'form name' | 'form object' (Method must be post)
                    ///      encode: true | false
                    ///      resultType: 'String'|'Xml'|'Json'|'Status',
                    ///      contentType:'application/x-www-form-urlencoded',
                    ///      onResponse:function(),
                    ///      onError:function(),
                    ///      onResponseHeader:function()
                    ///  }
                    ///	</param> 
                    (function (xH,s) {
                        if (isDefined(req.url)) { 
                            var format = isDefined(req.resultType) ? req.resultType : "JSON",_params = '';
                            if (isDefined(req.data)) {
                                _params = s.getParameters(req.data, req.url,
                                (isDefined(req.encode) ? true : false));
                            }
                            var req_method = isDefined(req.method) ? req.method : "Post";
                            if (xH !== null) {
                                xH.onreadystatechange = function () { 
                                    if (xH.readyState == 4) {
                                         if (xH.responseText.length > 0) {
                                                var result = "";
                                                var _st = xH.status;
                                                switch (format.toString().toUpperCase()) {
                                                    case 'STRING': result = xH.responseText; //Text
                                                        break;
                                                    case 'XML': result = xml.parse(xH.responseText);
                                                        break;
                                                    case 'JSON': result = xH.responseText;
                                                        if (typeof (JSON) !== 'undefined') {
                                                            result = JSON.parse(result);
                                                        }
                                                        break;
                                                    case 'STATUS': result = _st;
                                                        break;
                                                    default: result = xH.responseText;
                                                        break;
                                                }
                                                if (_st == 200) {
                                                    if (typeof req.onResponseHeader == 'function') {
                                                        req.onResponseHeader(xH.getAllResponseHeaders());
                                                    }
                                                    if (typeof req.onResponse == "function") {
                                                        req.onResponse(result);
                                                    }
                                                } else {
                                                    if (typeof req.onError == 'function') {
                                                        req.onError(_st, xH.statusText);
                                                    }
                                                }
                                         }
                                         xH = null;//End
                                    } 
                                };

                                var _par = null,_url = req.url;

                                if (isDefined(req.form)) {
                                   
                                    var formfields = st.forms.fetch(req.form),
                                    _ap = "";

                                    _par = "";
                                    for (var findex = 0, m = formfields.length; findex < m; findex++) {
                                        _par += _ap + formfields[findex].name + "=" + (isDefined(req.encode) ? encodeURIComponent(formfields[findex].value) : formfields[findex].value);
                                        _ap = "&";
                                    }
                                    var _s = s.ps(req.url);
                                    if (req_method.toLowerCase() === "get") {
                                        _url += _s + _par;
                                        _par = null;
                                    }

                                } else {
                                    //Get
                                    if (req_method.toLowerCase() === "get") {
                                        _url += _params;
                                    } else if (req_method.toLowerCase() === "post") {
                                        _par = _params.replace('?', '');
                                    }
                                }
                                var contentType = isDefined(req.contentType) ? req.contentType : "application/x-www-form-urlencoded";
                                if (isDefined(req.timeout)) {
                                    xH.timeout = req.timeout; 
                                }
                                if (isDefined(req.onTimeout)) {
                                    xH.ontimeout = req.onTimeout;
                                }
                                xH.open(req_method, _url, true);
                                xH.setRequestHeader("Content-type", contentType);
                                if (contentType === st.ajax.contentType.JSON) {
                                    xH.send(JSON.stringify(req.data));
                                } else {
                                    xH.send(_par);
                                }
                            } else {
                                req.onResponse("Browser doesn't support ajax");
                                req.onError("0", "Browser doesn't support ajax");
                            }
                        }
                    })(st.ajax.xmlhttpObject(), st.ajax.settings);
                   
                } 
            },
            // End of Ajax


            //Page and document 
            document: {
                height: function () {
                    ///<summary>
                    /// Return document height
                    ///</summary>
                    ///<returns type="number" />

                    return Math.max(
                        Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
                        Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
                        Math.max(document.body.clientHeight, document.documentElement.clientHeight)
                    );
                }
            },
            mouse:{
                coords: function (e) {
                    if (e.pageX || e.pageY) {
                        return { x: e.pageX, y: e.pageY };
                    }
                    return {
                        x: e.clientX + document.body.scrollLeft - document.body.clientLeft,
                        y: e.clientY + document.body.scrollTop - document.body.clientTop
                    };
                },
                offset: function (elem, e) { 
                    var ePos = st.page.pos(elem); 
                    var mPos = this.coords(e || window.event);
                    return { x: mPos.x - ePos.X, y: mPos.y - ePos.Y };
                },
                capture: function (fn) {
                    document.onmousemove = function (e) {
                        var pos = st.mouse.coords(e || window.event);
                        if (typeof fn === 'function') {
                            fn(pos);
                        }
                    };
                }
            },
            page: {
                onScroll: function (fn) {
                    ///	<summary>
                    ///	Attach an event when user scrolls.
                    ///	</summary>
                    ///<param name="fn" type="function">
                    ///	 Function to be executed
                    ///</param>
                    st.attach(window, 'scroll', fn); 
                },
                onScrollEvent: 0,
                onScrollToBottom: function (fn) {
                    ///	<summary>
                    ///	Attach an event when user scroll to the bottom of the page.
                    ///	</summary>
                    ///<param name="fn" type="function">
                    ///	 Function to be executed
                    ///</param>
                    st.page.onScroll(function () {
                       
                        if ((st.document.height() - st.page.height()) == st.page.scrollOffSet(window).Y) {
                            if (typeof(fn)==='function') {
                                fn();
                            }
                        }
                    });
                },
                height: function () {
                    ///<summary>
                    /// Return page height
                    ///</summary>
                    ///<returns type="number" />
                    if (window.innerHeight) {
                        return window.innerHeight;
                    } else {
                        return (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
                    }
                    return 0;
                },
                width: function () {
                    ///<summary>
                    ///	Return page width
                    ///</summary>
                    ///<returns type="number" />
                    if (window.innerWidth) {
                        return window.innerWidth;
                    } else {
                        return (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);
                    }
                    return 0;
                },
                scroll: {
                    to: function (x, y) {
                        ///	<summary>
                        ///	Scroll to a point in the screen
                        ///	</summary>
                        ///	<param name="x" type="number">
                        ///	 x value
                        ///	</param>
                        ///	<param name="y" type="number">
                        ///	 y value
                        ///	</param>
                        window.scrollTo(x, y);
                    },
                    top: function () {
                        ///	<summary>
                        ///	Scroll to a point (0,0) in the screen
                        ///	</summary> 
                        window.scrollTo(0, 0);
                    }
                },
                scrollOffSet: function (obj) {
                    ///	<summary>
                    ///	Get page offset X and Y for an object.
                    ///	</summary>
                    ///<param name="obj" type="DOM element">
                    ///	 If object is undefined "window" will be assumed.
                    ///</param>
                    ///<returns type="page offset (X,Y)" />

                    var r = { X: 0, Y: 0 };
                    obj = obj || window;

                    if (typeof (obj.pageXOffset) !== 'undefined') {
                        r.X = obj.pageXOffset;
                        r.Y = obj.pageYOffset;
                    } else {
                        //use document
                        var doc = obj.document;
                        if (typeof (doc) !== 'undefined') {
                            if (doc.compatMode === 'CSS1Compat') {
                                r.X = doc.documentElement.scrollLeft;
                                r.Y = doc.documentElement.scrollTop;
                            } else {
                                r.X = doc.body.scrollLeft;
                                r.Y = doc.body.scrollTop;
                            }
                        }
                       
                    }
                    return r;
                }, 
                pos: function (i) {
                    ///	<summary>
                    ///	Get position of an object in the screen.
                    ///	</summary>
                    ///<param name="id" type="identifier">
                    ///	 Element id, name, or reference
                    ///</param>
                    ///<returns type="point" />

                    var o = $(i),
                    point = {
                        X: 0,
                        Y: 0
                    };
                    if (o.offsetParent) {
                        if (o.offsetParent) {
                            do{
                                point.X += o.offsetLeft;
                                point.Y += o.offsetTop;
                            }while (o = o.offsetParent)
                        }
                    }
                    return point;
                }
            },
            //End of page

            extend: function (extension) {
                ///	<summary>
                ///	Extend SmallJS literal object.
                ///	</summary>
                ///	<param name="extension" type="object">
                ///	 Object to be attached
                ///	</param>
                var p = null;
                for (p in extension) {
                    if (isDefined(extension[p])) {
                        st[p] = extension[p];
                    }
                }
            }
        };
         
        st.extend({
            get:$
        });

        

        var local = {
            instance: function (plugins) {
                this.me = plugins.me;

                if (!(this instanceof local.instance)) {
                    throw new Error("Constructor called as a function");
                }
                
                if (isDefined(plugins)) {
                    for (var p in plugins) {
                        if (isDefined(plugins[p])) {
                            if (!isDefined(local.instance.prototype[p])) {
                                local.instance.prototype[p] = plugins[p];
                            } else if (p == 'me') {
                                local.instance.prototype[p] = plugins[p];
                            }
                        }
                    }
                }
                 
                this.get = $(this.me);

               
                this.forEach = function (fn) {
                    ///	<summary>
                    ///	Iterate over objects  
                    ///	</summary>
                    ///	<param name="fn" type="function">
                    ///	 Function to be executed for each element..
                    ///	</param>
                    for (var i = 0, m = this.me.length; i < m; i++) { 
                        if (typeof fn === 'function') {
                            fn.call(this.me[i]);
                        } 
                    }
                };

                this.removeAtt = function (name) {
                    ///	<summary>
                    ///	Remove an attribute from element
                    ///	</summary>
                    /// <param name="name" type="string">Attribute name</param>
                    this.forEach(function () {
                        $(this).removeAttribute(name);
                    });
                }
                this.hasAtt = function (name) {
                    ///	<summary>
                    ///	Check if attribute exists
                    ///	</summary>
                    /// <param name="name" type="string">Attribute name</param>
                    if (this.me.length > 0) {
                        var t = $(this.me[0]).getAttribute(name);
                        if (t) {
                            return true;
                        }
                    }
                    return false;
                };

                this.att = function (name,value) {
                    /// <signature>
                    ///   <summary>Read attribute from element</summary>
                    ///   <param name="name" type="string">Attribute name</param> 
                    ///	  <returns type="string|string[]" /> 
                    /// </signature>
                    /// <signature>
                    ///   <summary>Set attribute value</summary>
                    ///   <param name="name" type="string">Attribute name</param>
                    ///   <param name="value" type="string">Attribute value</param> 
                    ///	<returns type="this" /> 
                    /// </signature> 
                    var r = [];
                    this.forEach(function () {
                        if (isDefined(value)) {
                            $(this).setAttribute(name, value);
                        } else {
                            var t = $(this).getAttribute(name);
                            if (t) {
                                r.push(t);
                            }
                        }
                    });

                    if (isDefined(value)) {
                        return this;
                    }

                    if (r.length > 1) {
                        return r;
                    }

                    if (r.length == 1) {
                        return r[0];
                    }

                    return "";
                };

                this.call = function (req) {
                    ///	<summary>
                    ///	Perform an Ajax call
                    ///	</summary>
                    ///	<param name="req" type="json">
                    ///	 {
                    ///      method: 'Post'|'Get'|'Header',
                    ///      url: '',
                    ///      data: {
                    ///       'Param 1': 'Value 1',
                    ///       'Param 2': 'Value 2'
                    ///      },
                    ///      onTimeout:function(),
                    ///      timeout:'wait for response time',
                    ///      encode: true | false
                    ///      resultType: 'String'|'Xml'|'Json'|'Status',
                    ///      contentType:'application/x-www-form-urlencoded',
                    ///      onResponse:function(),
                    ///      onError:function(),
                    ///      onResponseHeader:function()
                    ///  }
                    ///	</param> 
                    this.forEach(function () {
                        sj(this).onClick(function () {
                            st.ajax.call({
                                url: req.url,
                                data: req.data,
                                onResponse: req.onResponse,
                                onError: req.onError,
                                onTimeout: req.onTimeout,
                                encode: req.encode,
                                resultType: req.resultType,
                                contentType: req.contentType,
                                onResponseHeader: req.onResponseHeader
                            });
                        });
                    });
                };

                this.text = function (content) {
                    /// <signature>
                    ///	<summary>
                    ///	Read content from innerHTML or value
                    ///	</summary> 
                    ///	<returns type="string|string[]" /> 
                    /// </signature>
                    /// <signature>
                    ///	<summary>
                    ///	Set content to an element's innerHTML or value.
                    ///	</summary>
                    ///	<param name="content" type="string">
                    ///	 Content to be set
                    ///	</param>
                    ///	<returns type="this" /> 
                    /// </signature>
                    for (var i = 0, m = this.me.length; i < m; i++) { 
                        var t = $(this.me[i]);
                        var usevalue = (t.tagName.toLowerCase() === 'input' || t.tagName.toLowerCase() === 'textarea');
                        var isSelect = (t.tagName === 'SELECT');
                        if (typeof content === 'undefined') {
                            if (isSelect) {
                                return st.forms.option.value(this.me[i]);
                            }
                            return usevalue ? t.value : t.innerHTML;
                        } else {
                            if (usevalue) {
                                t.value = content;
                            } else {
                                t.innerHTML = content;
                            }
                        }
                    }

                    return this;
                };

                this.attach = function (action, fn) {
                    ///<summary>
                    /// Attach an an event
                    ///</summary>
                    ///<param name="action" type="string">
                    /// Event action (ex. click, mouseOver, etc.)
                    ///</param>
                    ///<param name="fn" type="function">
                    /// Function to execute
                    ///</param> 
                    this.forEach(function () { st.attach(this, action, fn);}); 
                    return this;
                };

                this.on = this.attach;

                this.detach = function (action, fn) {
                    ///<summary>
                    /// Remove an event
                    ///</summary>
                    ///<param name="action" type="string">
                    /// Event action (ex. click, mouseOver, etc.)
                    ///</param>
                    ///<param name="fn" type="function">
                    /// Function to execute
                    ///</param> 
                    this.forEach(function () { st.detach(this, action, fn); });
                    return this;
                };
                
                this.onClick = function (fn) {
                    ///<summary>
                    /// Attach onClick event
                    ///</summary>
                    ///<param name="fn" type="function">
                    /// Function to execute
                    ///</param> 
                    this.forEach(function () {
                        st.attach(this, 'click', fn);
                    });
                    return this;
                };
                this.mouseOver = function (fn) {
                    ///<summary>
                    /// Attach to mouse over and out events
                    ///</summary>
                    ///<param name="fn" type="function">
                    /// Function to execute onmouseover
                    ///</param>  
                    this.forEach(function () {
                        if (typeof (fn) === 'function') {
                            st.attach(this, 'mouseover', fn);
                        } 
                    });
                    return this;
                };

                this.mouseOut = function (fn) {
                    ///<summary>
                    /// Attach to mouse over and out events
                    ///</summary> 
                    ///<param name="fn" type="function">
                    /// Function to execute onmouseout
                    ///</param> 
                    this.forEach(function () {
                        if (typeof (fn) === 'function') {
                            st.attach(this, 'mouseout', fn)
                        }
                    });
                    return this;
                };

                this.style = function () {
                    ///	<summary>
                    ///	Add CSS style elements as parameters.
                    /// Example:
                    /// .style('width:100px',
                    ///      'border:1px solid #333333',
                    ///      'color:#dddddd');
                    ///	</summary>
                    ///	<returns type="this" />   

                    if (arguments.length >= 1) {
                        var newstyle = [];
                        for (var i = 0, m = arguments.length; i < m; i++) {
                            if (arguments[i].contains(':')) {
                                newstyle.push(arguments[i]);
                            }
                        }
                        this.forEach(function () {
                            var current = (window.attachEvent) ? $(this).style.cssText : $(this).getAttribute('style');
                            if (current == null) { current = ''; }
                            var txt = '';
                            var sc = current.split(';');
                            var excl = [];
                            for (var i = 0,mi = sc.length; i < mi; i++) {
                                var term = sc[i].split(':');
                                for (var ns = 0, nsm = newstyle.length; ns < nsm; ns++) {
                                    var nterm = newstyle[ns].split(':');
                                    if (nterm[0] == term[0]) {
                                        sc[i] = newstyle[ns];
                                        excl.push(ns);
                                    }
                                }
                                if (sc[i].length > 1) {
                                    txt += sc[i].replace(';', '') + ';';
                                }
                            }
                            for (var en = 0, enm = excl.length; en < enm; en++) {
                                newstyle.splice(excl[en], 1);
                            }
                            for (var ns = 0, nsm = newstyle.length; ns < nsm; ns++) {
                                if (newstyle[ns].length > 1) {
                                    txt += newstyle[ns].replace(';', '') + ';';
                                }
                            }
                            if (window.attachEvent) {
                                $(this).style.cssText = txt;
                            } else {
                                $(this).setAttribute('style', txt);
                            }

                        });

                    }

                    return this;
                };

                this.hasStyle = function (style) {
                    ///	<summary>
                    ///	Returns true is style exists in the element.
                    /// Example:
                    /// Is style 'width:100px' defined in element 'id'?
                    /// sj('id').hasStyle('width:100px'); 
                    ///
                    /// Is style 'width' defined in element 'id'?
                    /// sj('id').hasStyle('width');
                    ///	</summary>
                    ///	<returns type="Boolean" />   
                    if (this.me.length == 0) { return false; }

                    var current = (window.attachEvent) ? $(this.me[0]).style.cssText : $(this.me[0]).getAttribute('style');
                    if (current == null) { return false; }
                    var sc = current.split(';');
                    var to = '';
                    var val = '*';
                    if (style.contains(':')) {
                        var spl = style.split(':');
                        to = spl[0];
                        val = spl[1];
                    } else {
                        to = style;
                    }
                    for (var i = 0, m = sc.length; i < m; i++) {
                        var term = sc[i].split(':');
                        if (term.length == 2) {
                            if (val != '*') {
                                if (term[0].toLowerCase().trim() === to.toLowerCase().trim() && term[1].toLowerCase().trim() === val.toLowerCase().trim()) {
                                    return true;
                                }
                            } else {
                                if (term[0].toLowerCase().trim() === to.toLowerCase().trim()) {
                                    return true;
                                }
                            }
                        }
                    }
                    return false;
           
                };
            
                this.classExists = function (className) {
                    ///	<summary>
                    /// Does css class already exists?
                    ///	</summary>
                    ///	<param name="className" type="string">
                    /// CSS class name
                    ///	</param> 
                    ///	<returns type="Boolean" /> 
                    if (this.me.length > 0) {
                        var i = $(this.me[0]);
                        if (isDefined(i)) { 
                            return new RegExp('(?:^|\\s)' + className + '(?!\\S)').test(i.className); 
                        }
                        return false;
                    }
                    return false;
                };

                this.addClass = function (className) {
                    ///	<summary>
                    /// Add a css class
                    ///	</summary>
                    ///	<param name="className" type="string">
                    /// CSS class name
                    ///	</param> 
                    ///	<returns type="this" /> 
                    this.forEach(function () {
                        if (isDefined(this.className)) {
                            if (this.className.length <= 0) {
                                this.className = className;
                            } else {
                                if (!_css.exists(this, className)) {
                                    var current = this.className;
                                    this.className = className + ' ' + current;
                                }
                            }
                        }
                        
                    });

                    return this;
                };

                this.removeClass = function (className) {
                    ///	<summary>
                    /// Remove CSS class
                    ///	</summary>
                    ///	<param name="className" type="string">
                    /// CSS class name
                    ///	</param> 
                    ///	<returns type="this" /> 
                    this.forEach(function () {
                        if (isDefined(this.className)) { 
                            if (sj(this).classExists(className)) {
                                this.className = this.className.replace(new RegExp('(?:^|\\s)' + className + '(?!\\S)'), '');
                            } 
                        } 
                    });
                    return this;
                };

                this.replaceClass = function (originalClass, newClass) {
                    ///	<summary>
                    /// Replace a CSS class
                    ///	</summary>
                    ///	<param name="originalClass" type="string">
                    /// Original class name
                    ///	</param> 
                    ///	<param name="newClass" type="string">
                    /// New class name
                    ///	</param> 
                    ///	<returns type="this" /> 
                    this.removeClass(originalClass);
                    this.addClass(newClass);
                };

                this.toggleClasses = function (class1, class2) {
                    ///	<summary>
                    /// Toggle between two CSS classes
                    ///	</summary>
                    ///	<param name="class1" type="string">
                    /// CSS class name
                    ///	</param> 
                    ///	<param name="class2" type="string">
                    /// CSS class name
                    ///	</param> 
                    ///	<returns type="this" /> 
                    this.forEach(function () {
                      
                        if (sj(this).classExists(class1)) {
                            sj(this).replaceClass(class1, class2);
                        } else {
                            sj(this).replaceClass(class2, class1);
                        }
                    });
                };

                this.submitAsynch = function (_params) {
                    ///	<summary>
                    ///	Submit a form via ajax
                    ///	</summary>
                    ///	<param name="_params" type="object">
                    ///	 {
                    ///     url:'processing url',
                    ///     onResponse:function(),
                    ///     onError:function()
                    ///  }
                    ///	</param>
                    ///	<returns type="this" /> 
                    this.forEach(function () {
                        st.ajax.call({
                            url: _params.url,
                            form: $(this),
                            onResponse: _params.onResponse,
                            onError: _params.onError,
                            encode: true
                        });
                    });
                    return this;
                };

                this.delegate = function (child, action, fn) {
                    ///	<summary>
                    ///	Delegate event handling to a parent
                    ///	</summary>
                    ///	<param name="child" type="string">
                    ///	 child tag or identifier or selector
                    ///	</param> 
                    ///	<param name="action" type="string">
                    ///	 Action or event to delegate
                    ///	</param> 
                    ///	<param name="fn" type="string">
                    ///	 Function to execute
                    ///	</param> 

                    this.forEach(function () {
                        var p = this;
                        st.attach(p, action, function (event) {
                            event = event || window.event;
                            var target = event.target || event.srcElement;
                            var children = $(p).getElementsByTagName(child);
                            if (children.length == 0) {
                                if ($(p).querySelectorAll) {
                                    children = $(p).querySelectorAll(child);
                                } else if (window.Sizzle) {
                                    if (isDefined(p.id)) {
                                        var id = ((!p.id.contains('#')) ? '#' + p.id : p.id) + ' ' + child;
                                        children = Sizzle(id);
                                    }
                                }
                            }
                            if (children.length > 0) {
                                for (var i = 0, m = children.length; i < m; i++) {
                                    if (target.id.length > 0) {
                                        if (target.id == children[i].id) { fn.call(children[i]); }
                                    } else {
                                        if (target == $(children[i])) { fn.call(children[i]); }
                                    }
                                }
                            } else {
                                if (target.id.length > 0) {
                                    if (target.id == children.id) { fn.call(children); }
                                } else {
                                    if (target == children) { fn.call(children); }
                                }
                            }
                        });
                    });

                    return this;
                };

                this.upload = function (params) {
                    ///	<summary>
                    ///	Upload file(s)
                    ///	</summary>
                    ///	<param name="params" type="json">
                    ///	 {
                    ///	     url:'',
                    ///      onError:function(),
                    ///      onAbort:function(),
                    ///      onLoad:function(),
                    ///      onLoadStart:function(),
                    ///      onLoadEnd:function(),
                    ///      onProgress:function(),
                    ///      onTimeout:function(),
                    ///      onResponse:function()
                    ///  }
                    ///	</param>   ar
                    this.forEach(function () {
                        if ($(this).files.length > 0) {
                            var file = $(this).files[0];
                            st.ajax.file({
                                url: params.url,
                                file: file,
                                onProgress: params.onProgress,
                                onError: params.onError,
                                onAbort: params.onAbort,
                                onLoad: params.onLoad,
                                onLoadStart: params.onLoadStart,
                                onLoadEnd: params.onLoadEnd,
                                onTimeout: params.onTimeout,
                                onResponse: params.onResponse
                            });
                        }
                    });
                    return this;
                };

                this.appendText = function (content) {
                    ///	<summary>
                    ///	Append text to an element
                    ///	</summary>
                    ///	<param name="content" type="string">
                    ///	 Content to append
                    ///	</param>  
                    this.forEach(function () { sj(this).text(sj(this).text() + content); });
                    return this;
                };

                this.isEmpty = function () {
                    ///	<summary>
                    ///	Is innerHTML or Value empty
                    ///	</summary> 
                    ///	<returns type="Boolean" /> 
                    var r = false;
                    this.forEach(function () { r = sj(this).text().replace(/^\s+|\s+$/g, "").length == 0; });
                    return r;
                };

                this.removeAllChildren = function () {
                    ///	<summary>
                    ///	Remove all children from a DOM element
                    ///	</summary>
                    this.forEach(function () {
                        if ($(this).hasChildNodes()) {
                            while ($(this).childNodes.length >= 1) {
                                $(this).removeChild($(this).firstChild);
                            }
                        }
                    });
                    return this;
                };
                
                this.insertChildBefore = function (node) {
                    ///	<summary>
                    ///	Insert node before (this node)
                    ///	</summary>
                    ///	<param name="node" type="Node object">
                    ///	Required. The node object you want to insert
                    ///	</param>
                    this.forEach(function () {
                        var c = node.cloneNode(true);
                        this.parentNode.insertBefore(c, this);
                        node.parentNode.insertBefore(this, node);
                        node.parentNode.replaceChild(node, c);
                    }); 
                };

                this.insertChildAfter = function (node) {
                    ///	<summary>
                    ///	Insert node after (this node)
                    ///	</summary>
                    ///	<param name="node" type="Node object">
                    ///	Required. The node object you want to insert
                    ///	</param>
                    this.forEach(function () {
                        this.parentNode.insertBefore(node, this.nextSibling);
                    });
                    return this;
                };

                this.appendChild = function (node) {
                    ///	<summary>
                    ///	Shortcut to node.appendChild(node)
                    ///	</summary>
                    ///	<param name="node" type="Node object">
                    ///	Required. The node object you want to append
                    ///	</param>
                    this.forEach(function () {
                        $(this).appendChild(node);
                    });
                    return this;
                };
                this.hasChildNodes = function () {
                    ///	<summary>
                    ///	Does the DOM element has child nodes?
                    ///	</summary>
                    if (this.me.length > 0) {
                        return $(this.me[0]).hasChildNodes();
                    }
                    return false;
                }
                this.remove = function () {
                    ///	<summary>
                    ///	Remove element from DOM
                    ///	</summary>
                    this.forEach(function () {
                        this.parentNode.removeChild(this);
                    });
                    return this;
                };

                this.clone = function (deep) {
                    ///	<summary>
                    ///	Abstracting cloneNode(true)
                    ///	</summary>
                    ///	<param name="deep" type="boolean">
                    ///	True if the children of the node should also be cloned, or false to clone only the specified node.
                    ///	</param>
                    if (this.me.length > 0) {
                        if (!isDefined(deep)) {
                            deep = true;
                        }
                        return $(this.me[0]).cloneNode(deep);
                    }
                    return null;
                }

                this.children = function (expr) {
                    ///	<summary>
                    ///	Find child elements and return them as an array
                    ///	</summary>
                    ///	<param name="expr" type="string">
                    ///	 Selection expression (ex. .className or ul.className)
                    ///	</param>
                    var o = [];
                
                    if (this.me.length > 0) {
                        var ch = $(this.me[0]).querySelectorAll(expr);
                        for (var i = 0, max = ch.length; i < max; i++) {
                            o.push(ch[i]);
                        }
                    } 
                    return o;
                };

                this.select = function (expr) {
                    ///	<summary>
                    ///	Select elements and return them as an array of sj() objects
                    ///	</summary>
                    ///	<param name="expr" type="string">
                    ///	 Selection expression (ex. .className or ul.className)
                    ///	</param>
                    var o = $(this.me[0]).querySelectorAll(expr), r = [], i = 0, m = 0;
                    for (i = 0,m=o.length; i < m; i++) {
                        r.push(sj(o[i]));
                    } 
                    return r;
                };

            

                this.position = function () {
                    ///	<summary>
                    ///	Returns an element's position.
                    ///	</summary>
                    ///	<param name="position" type="JSON">
                    ///	 { X,Y }
                    ///	</param>
                    return st.page.pos(this.me[0]);
                };

                this.isDisplayOn = function () {
                    ///	<summary>
                    ///	Check if the display style is 'block'
                    ///	</summary>
                    if (this.me.length > 0) {
                        return $(this.me[0]).style.display == 'block';
                    }
                    return false;
                };
                 
                this.displayDefault = function () {
                    ///	<summary>
                    ///	Set display style to 'inherit'
                    ///	</summary>
                    this.forEach(function () {
                        $(this).style.display = 'inherit'; 
                    });
                    return this;
                }
                this.displayOn = function () {
                    ///	<summary>
                    ///	Set display style to 'block'
                    ///	</summary>
                    this.forEach(function () { 
                        $(this).style.display = 'block';
                    });
                    return this;
                };
                
                this.displayOff = function () {
                    ///	<summary>
                    ///	Set display style to 'none'
                    ///	</summary>
                    this.forEach(function () {
                        $(this).style.display = 'none';
                    });
                    return this;
                };

                this.displaySwap = function () {
                    ///	<summary>
                    ///	Swap display style between 'none' and 'block'
                    ///	</summary>
                    this.forEach(function () {
                        if ($(this).style.display === 'block') {
                            sj(this).displayOff();
                        } else {
                            sj(this).displayOn();
                        }
                    });

                    return this;
                };

                //end of instance()
            }
        };

        var _css = {
            exists: function (id,className) {  
                    if (isDefined($(id))) {
                        return new RegExp('(?:^|\\s)' + className + '(?!\\S)').test($(id).className);
                    }
                    return false;
         
            }
        };
              
         
        var plugins = {
            me:null
        };

        st.extend({
            plugin: function (extension) {
                ///	<summary>
                ///	Add a plugin to SmallJS
                ///	</summary>
                ///	<param name="extension" type="object">
                ///	 {
                ///     method:function(){
                ///         this.forEach(function(){
                ///             console.log(this.innerHTML);
                ///         });
                ///      }
                ///  }
                ///	</param> 
                for (var p in extension) {
                    if (isDefined(extension[p])) {
                        if(!isDefined(plugins[p])){
                            plugins[p] = extension[p];
                        }
                    }
                }
            }
        });
   
        return sj;

    })();


    //Augment the Function object
    //Thanks to Douglas Crockford (http://www.crockford.com/javascript/inheritance.html#sugar)
    if (!Function.method) {
        Function.prototype.method = function (name, fn) {
            ///<summary>
            ///	Add a method to a function
            ///</summary>
            ///<param name="name" type="string">
            ///	 Method name
            ///</param>
            ///<param name="fn" type="function">
            ///	 Function
            ///</param>
            ///<returns type="object" />
            this.prototype[name] = fn;
            return this;
        };
    }
    if (!Function.inherits) {
        Function.prototype.inherits = function (parent) {
            ///<summary>
            ///	Inherit methods from a parent object
            ///</summary>
            ///<param name="name" type="string">
            ///	 Parent object
            ///</param> 
            ///<returns type="object" />
            this.prototype = new parent();
            var d = {},
                p = this.prototype;
            this.prototype.constructor = parent;
            this.method('uber', function uber(name) {
                if (!(name in d)) {
                    d[name] = 0;
                }
                var f, r, t = d[name], v = parent.prototype;
                if (t) {
                    while (t) {
                        v = v.constructor.prototype;
                        t -= 1;
                    }
                    f = v[name];
                } else {
                    f = p[name];
                    if (f == this[name]) {
                        f = v[name];
                    }
                }
                d[name] += 1;
                r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
                d[name] -= 1;
                return r;
            });
            return this;
        };
    }

    (function (s) {
        if (!s.contains) {
            s.method("contains", function (substring) {
                return this.indexOf(substring) != -1;
            });
        }
        if (!s.truncate) {
            s.method("truncate", function (max) {
                return this.substr(0, max);
            });
        }
        if (!s.fromHtml) {
            s.method("fromHtml", function () {
                return this.replace(/</g, '&lt;').replace(/>/g, '&gt;');
            });
        }
        if (!s.trimRight) {
            s.method("trimRight", function () {
                return this.replace(/\s+$/g, "");
            });
        }
        if (!s.trimLeft) {
            s.method("trimLeft", function () {
                return this.replace(/^\s+/g, "");
            });
        }
        if (!s.trim) {
            s.method("trim", function () {
                return this.replace(/^\s+|\s+$/g, "");
            });
        }
    })(String);
     
 
    if (!window.sj) {
        window.sj = SmallJS;
    }

    if (!window.smalljs) {
        window.smalljs = SmallJS();
    }
    if (!window.get) {
        window.get = SmallJS().get;
    }

})();